package com.zhangqiang.git.cloud.remote.factory;

import com.zhangqiang.git.cloud.domain.consumer.SysUser;
import com.zhangqiang.git.cloud.remote.model.RemoteUserService;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 用户服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public SysUser findUserByName(String username)
            {
                System.out.println("获取用户失败:" + throwable.getMessage());
                return null;
            }

            @Override
            public List<String> findRolesByUser(String userId)
            {
                System.out.println("获取用户权限失败:" + throwable.getMessage());
                return null;
            }
        };
    }
}
